<?php
/**
 * Created by PhpStorm.
 * User: MADAO
 * Date: 2019/9/28
 * Time: 11:37
 */

namespace App\Services;

class AuthService
{
    public function getNoSuperMenus($authUser)
    {
        /**
         * @var \App\Model\User $authUser
         */
        $roles = $authUser->roles()->with('menus')->get();
        $ownedMenus = collect([]);
        $roles->each(function ($role) use (&$ownedMenus) {
            /**
             * @var \App\Model\Role $role
             */
            $ownedMenus = $ownedMenus->merge($role->menus);
        });
        return $ownedMenus->unique('id')->sortBy('sort')->toArray();
    }
}
